//  array  list [0,11]
let fruits = ["apple", "banana", "pear", "orange"];
// for i
for (let i = 0; i < fruits.length; i++) {
  let ee = fruits[i];
  console.log(ee.toUpperCase());
}
// for of  js 里的for of 对标其他语言for in

for (let ee of fruits) {
  console.log(ee);
}

// filter
let r = fruits.filter((element) => {
  return element.includes("e");
});

fruits = ["apple", "banana", "pear", "orange"];
let fruitsEx = [];
for (let i = 0; i < fruits.length; i++) {
  if (fruits[i].includes("e")) {
    fruitsEx.push(fruits[i]);
  }
}
// console.log(fruitsEx);
// this[i].includes("e")
/* 
fruits.filter2 = function (predict) {
  let fruitsEx = [];
  for (let i = 0; i < this.length; i++) {
    let s = predict(this[i]);
    if (s) {
      fruitsEx.push(this[i]);
    }
  }
  return fruitsEx;
};
let p = function(e){
    return e.includes("e")
}
fitler.filter2(p) 
*/
// filter 传入的函数 对于 函数入参 和返回值有要求
// 入参 代表 数组的每一个元素， 返回值 必须是boolean
let c = function (e) {
  console.log("xxx" + e);
  return e.includes("an");
};
let re = fruits.filter(c);

// A容器如下["apple", "banana", "pear", "orange","peach"] ，
// B1,B2,B3容器均为空容器 []
// 使用for of语句 请将A容器内的元素分别按下列条件添加到B1,B2,B3容器内
// 1 元素名字以字母p开头;             -> B1 ["pear","peach"]
// 2 元素名字包含字母r；              -> B2 ["pear","orange"]
// 3 元素名字长度大于等于5；           -> B3 ["apple", "banana","orange","peach"]
let A = ["apple", "banana", "pear", "orange", "peach"];
let B1 = [];
for (let element of A) {
  let a = element.startsWith("p");
  if (a) {
    B1.push(element);
  }
}


B1 = A.filter((_) => {
  return _.startsWith("p");
});
let B2 = [];
for (let element of A) {
  let a = element.includes("r");
  if (a) {
    B2.push(element);
  }
}
B2 = A.filter((element) => {
  return element.includes("r");
});

function t1(e){
    console.log(e);
    return true;
}

let t2 = function(e){
    console.log(e);
    return false;
}
let t3 = (e)=>{
    console.log(e);
    return true;
}

// 传入一个方法体 方法体入参有一个，返回值是布尔类型
A.filter(t1)
A.filter(t2)
A.filter(t3)
A.filter((e)=>{
    console.log(e);
    return true;
});

let A1 = A.filter((c)=>{
   return c.startsWith("p");
})
// Predict 断言 维词  一个任意类型的入参 ，一个Boolean返回值
// Function x - y    一个任意类型的入参 ，一个任意类型的返回值
// Consume消费        一个任意类型的入参 ，没有返回值
// Produce生产        没有入参，一个任意类型的返回值
let A2 = A.forEach((e)=>{
    console.log("______");
    e=e+"xxxx"
    console.log(e);
    console.log("______");
})
let A3 = A.map(e=>{
    return e=e+"xxxx";
})
